<html>
<head><meta charset="utf-8"><title>loop label shadowing confusion · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/loop.20label.20shadowing.20confusion.html">loop label shadowing confusion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204634010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/loop%20label%20shadowing%20confusion/near/204634010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/loop.20label.20shadowing.20confusion.html#204634010">(Jul 22 2020 at 06:28)</a>:</h4>
<p>When using more than one labeled loop of the same name within the same block, rust reports them as shadowing each other even when they're one <em>after</em> the other instead of one <em>inside of</em> the other:</p>
<div class="codehilite"><pre><span></span><code><span class="na">&#39;name</span>: <span class="nc">loop</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="na">&#39;name</span>: <span class="nc">loop</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="c1">// rustc thinks that this `&#39;name` &quot;shadows&quot; the previous one</span>
</code></pre></div>


<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=659f38bed609fc342ebb4c231f306ac3">minimal playground example</a><br>
Is this just a false warning? When you run the program it prints "passed 10" and then "passed 20" exactly as one might expect. The second loop can't actually <code>continue</code> back to the first loop or anything weird.</p>



<a name="204635599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/loop%20label%20shadowing%20confusion/near/204635599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/loop.20label.20shadowing.20confusion.html#204635599">(Jul 22 2020 at 07:01)</a>:</h4>
<p>I think so <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> this shouldn't warn imo</p>



<a name="204638182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/loop%20label%20shadowing%20confusion/near/204638182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/loop.20label.20shadowing.20confusion.html#204638182">(Jul 22 2020 at 07:47)</a>:</h4>
<p>This is actually by design - <a href="https://github.com/rust-lang/rust/pull/24162">https://github.com/rust-lang/rust/pull/24162</a>.</p>



<a name="204638258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/loop%20label%20shadowing%20confusion/near/204638258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/loop.20label.20shadowing.20confusion.html#204638258">(Jul 22 2020 at 07:48)</a>:</h4>
<p>But not in macros - <a href="https://github.com/rust-lang/rust/issues/24278">https://github.com/rust-lang/rust/issues/24278</a> <a href="https://github.com/rust-lang/rust/issues/65269">https://github.com/rust-lang/rust/issues/65269</a>.</p>



<a name="204638391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/loop%20label%20shadowing%20confusion/near/204638391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/loop.20label.20shadowing.20confusion.html#204638391">(Jul 22 2020 at 07:50)</a>:</h4>
<p>Not sure whether the original root issue (<a href="https://github.com/rust-lang/rust/issues/21633">https://github.com/rust-lang/rust/issues/21633</a>) is still relevant, but the issues about unsuppressable warnings and wrong hygiene are certainly still relevant.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>